<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    #clock{
        height:50px;
        line-height: 50px;
        text-align: center;
    }
    </style>
</head>
<body>
    <div class="clock" id="clock">

    </div>
    <script>
		function addZero(n){
			return n<10?"0"+n:n;
	    }
		
      function clock(){
        var time=new Date;
        var year=time.getFullYear();
        var month=time.getMonth()+1;//0-11 代表1月到12月
        var date=time.getDate();//日期
        var day=time.getDay();//0-6代表周日到到六
        var hours=time.getHours();
        var minutes=time.getMinutes();
        var seconds=time.getSeconds();

        var weekStr=["日","一","二","三","四","五","六"];
        var week=weekStr[day];
		
        var result=year+"年"+ month+"月"+date+"日"+ "周" + week
		+addZero(hours)+"时"+addZero(minutes)+"分"+addZero(seconds)+"秒";
		
        return result;
		
		}

      var time=clock();
      document.getElementById("clock").innerHTML=time;

      setInterval(function(){
          var time=clock();
          document.getElementById("clock").innerHTML=time;
      },1000)
    </script>
</body>
</html>
